#ifndef _MAIN_H
#define _MAIN_H

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>

#include <sys/stat.h>
#include <fcntl.h>
#include <sqlite3.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <signal.h>

#include "coord.h"
#include "linkqueue.h"

#define size 256

/*定义结构体*/
typedef struct moni_msg
{
	unsigned char zgno; //节点编号
	unsigned char tem[2]; //温度
	unsigned char hum[2]; //湿度
	unsigned char lux[2]; //光强
} MSG;

typedef struct moni_info
{
	int zgno; //节点编号
	float temper; //温度
	float humi; //湿度
	unsigned int illum; //光强
	unsigned char dev_stat; //执行机构状态 0关 1开
} INFO;

/*全局变量*/
extern char mobilebuf[size];//移动端和服务端通信的字符串
extern char quedata[size];
extern char validdata[7];//有效的7个字节数据
extern MSG msg;
extern INFO info;
extern pthread_mutex_t mutex;
extern pthread_cond_t cond;
extern char mob_str[4][20];

extern sqlite3* pdb;
extern char sql[size];
extern char*errmsg;
extern char** result;
extern int row,col;

extern link_pqueue pque;


/*函数声明*/
void* coord_thread(void *arg);
void* outqueue_thread(void *arg);
void* mob_thread(void *arg);
int login(int newfd,char* username,char* password);
void regis(int newfd,char* username,char* password);
void control(int newfd,char* devname,char* devstat);
void change_devstat(int dev, int stat);
void req_paras(int newfd,char* username,char* password);
void get_paras(int newfd);



#endif


